package kpi.javatraining6.gnatiuk.tests;

import kpi.javatraining6.gnatiuk.src.tester.Authorizer;
import kpi.javatraining6.gnatiuk.src.tester.readers.UserDOMSaver;
import kpi.javatraining6.gnatiuk.src.tester.user.AdminController;
import kpi.javatraining6.gnatiuk.src.tester.user.User;
import kpi.javatraining6.gnatiuk.src.tester.user.UserController;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

import static org.junit.Assert.*;

public class AuthorizerTest {

    Authorizer authorizer;
    User user;
    @Before
    public void setUp() throws IOException, ClassNotFoundException {
        user = new User("jack", "jack");
        authorizer = new Authorizer();
        authorizer.authenticateUser(user);
    }


    @Test
    public void testWrongPassword() throws Exception{
        User someUser = new User("jack", "wrong");
        assertFalse(authorizer.authenticateUser(someUser));
    }



    @Test
    public void testGetUserController() throws Exception{
        authorizer.authenticateUser(user);
        Class userControllerClazz  = authorizer.getUserController().getClass();
         assertEquals("must be same class", UserController.class, userControllerClazz);
    }

    @Test
    public void testGetAdminController() throws Exception{
        user = new User("admin", "admin");
        authorizer.authenticateUser(user);
        Class adminControllerClazz  = authorizer.getUserController().getClass();
        assertEquals("must be same class", AdminController.class, adminControllerClazz);
    }

}
